package com.ruoyi.oa.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oa.domain.LeaveTeacher;
import com.ruoyi.oa.service.ILeaveTeacherService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师请假Controller
 * 
 * @author 张艳羽
 * @date 2024-10-10
 */
@Controller
@RequestMapping("/leave/leaveTea")
public class LeaveTeacherController extends BaseController
{
    private String prefix = "leave/leaveTea";

    @Autowired
    private ILeaveTeacherService leaveTeacherService;

    @RequiresPermissions("leave:leaveTea:view")
    @GetMapping()
    public String leaveTea()
    {
        return prefix + "/leaveTea";
    }

    /**
     * 查询教师请假列表
     */
    @RequiresPermissions("leave:leaveTea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LeaveTeacher leaveTeacher)
    {
        startPage();
        List<LeaveTeacher> list = leaveTeacherService.selectLeaveTeacherList(leaveTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师请假列表
     */
    @RequiresPermissions("leave:leaveTea:export")
    @Log(title = "教师请假", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LeaveTeacher leaveTeacher)
    {
        List<LeaveTeacher> list = leaveTeacherService.selectLeaveTeacherList(leaveTeacher);
        ExcelUtil<LeaveTeacher> util = new ExcelUtil<LeaveTeacher>(LeaveTeacher.class);
        return util.exportExcel(list, "教师请假数据");
    }

    /**
     * 新增教师请假
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教师请假
     */
    @RequiresPermissions("leave:leaveTea:add")
    @Log(title = "教师请假", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LeaveTeacher leaveTeacher)
    {
        return toAjax(leaveTeacherService.insertLeaveTeacher(leaveTeacher));
    }

    /**
     * 修改教师请假
     */
    @RequiresPermissions("leave:leaveTea:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LeaveTeacher leaveTeacher = leaveTeacherService.selectLeaveTeacherById(id);
        mmap.put("leaveTeacher", leaveTeacher);
        return prefix + "/edit";
    }

    /**
     * 修改保存教师请假
     */
    @RequiresPermissions("leave:leaveTea:edit")
    @Log(title = "教师请假", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LeaveTeacher leaveTeacher)
    {
        return toAjax(leaveTeacherService.updateLeaveTeacher(leaveTeacher));
    }

    /**
     * 删除教师请假
     */
    @RequiresPermissions("leave:leaveTea:remove")
    @Log(title = "教师请假", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(leaveTeacherService.deleteLeaveTeacherByIds(ids));
    }

    /**
     * 审批通过教师请假
     */
    @RequiresPermissions("leave:leaveTea:edit")
    @PostMapping( "/approve")
    @ResponseBody
    public AjaxResult approve(String status, String ids)
    {
        return toAjax(leaveTeacherService.updateLeaveTeaStatus(status, ids));
    }
}
